package com.shihb.structuralpatterns.adapterpatterns;/**
 *Description:
 *Version:1.0.0
 *@author shihb
 *@date 2020/7/15 20:51
 */
public class ClassAdapter {

  public static void main(String[] args) {


    Phone phone = new Phone();
    Voltage5v adapter= new VoltageAdapter();
    phone.charging(adapter);
  }
}

//目标
interface Voltage5v{
   int out5V();
}
//适配器，继承关系不好，耦合
class VoltageAdapter extends Voltage220v implements Voltage5v{
  @Override
  public int out5V() {
    int src = out220v();
    return src/44;
  }
}
// 适配对象
class Voltage220v{

  public int out220v(){
    int src=220;
    System.out.println("电压是"+src+"V");
    return src;
  }
}
class Phone{
  void charging(Voltage5v adapter){

    if(adapter.out5V()==5){
      System.out.println("5v充电成功");
    }else {
      System.out.println("不是5v，充电失败");

    }
  }
}
